package com.mandala.service;

import org.springframework.stereotype.Service;

import com.mandala.entry.ResponseWrapper;
@Service
public class JsonResult {
	
	private static final String SUCCESS = "0000";//SUCCESS("0000","查询成功"),
	private static final String SUCCESS_MSG = "查询成功";
	private static final String NODATA = "0001";//NODATA("0001","查询成功无记录"),
	private static final String NODATA_MSG = "查询成功无记录";
	private static final String FEAILED = "0002";//FEAILED("0002","查询失败"),
	private static final String FEAILED_MSG = "查询失败";
	private static final String PARAMS_ERROR = "1004";//PARAMS_ERROR("1004", "参数为空或格式错误"),
	private static final String PARAMS_ERROR_MSG = "参数为空或格式错误";
	private static final String SYSTEM_ERROR = "9999";//PARAMS_ERROR("1004", "参数为空或格式错误"),
	private static final String SYSTEM_ERROR_MSG = "系统异常";
	
	/*SUCCESS("0000","查询成功"),
    NODATA("0001","查询成功无记录"),
    FEAILED("0002","查询失败"),
    API_NOT_EXISTS("1001", "请求的接口不存在"),
    API_NOT_PER("1002", "没有该接口的访问权限"),
    PARAMS_ERROR("1004", "参数为空或格式错误"),
    API_DISABLE("1011", "查询权限已被限制"),
    UNKNOWN_IP("1099", "非法IP请求"),
    SYSTEM_ERROR("9999", "系统异常");*/
	 /**
     * 自定义返回结果
     * 建议使用统一的返回结果，特殊情况可以使用此方法
     * @param success
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public  ResponseWrapper markCustom(boolean success,String code,String msg,String data){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setSuccess(success);
        responseWrapper.setCode(code);
        responseWrapper.setMsg(msg);
        responseWrapper.setData(data);
        return responseWrapper;
    }
 
    /**
     * 参数为空或者参数格式错误
     * @return
     */
    public  ResponseWrapper markParamError(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setSuccess(false);
        responseWrapper.setCode(PARAMS_ERROR);
        responseWrapper.setMsg(PARAMS_ERROR_MSG);
        return responseWrapper;
    }
 
    /**
     * 查询失败
     * @return
     */
    public  ResponseWrapper markError(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setSuccess(false);
        responseWrapper.setCode(FEAILED);
        responseWrapper.setMsg(FEAILED_MSG);
        responseWrapper.setData(null);
        return responseWrapper;
    }
    
    public  ResponseWrapper markConnectError(){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setSuccess(false);
        responseWrapper.setCode(SYSTEM_ERROR);
        responseWrapper.setMsg(SYSTEM_ERROR_MSG);
        responseWrapper.setData(null);
        return responseWrapper;
    }
 
    /**
     * 查询成功但无数据
     * @return
     */
    public  ResponseWrapper markSuccessButNoData(){
        ResponseWrapper responseWrapper  = new ResponseWrapper();
        responseWrapper.setSuccess(true);
        responseWrapper.setCode(NODATA);
        responseWrapper.setMsg(NODATA_MSG);
        responseWrapper.setData("[]");
        return responseWrapper;
    }
 
    /**
     * 查询成功且有数据
     * @param data
     * @return
     */
    public  ResponseWrapper markSuccess(Object data){
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setSuccess(true);
        responseWrapper.setCode(SUCCESS);
        responseWrapper.setMsg(SUCCESS_MSG);
        responseWrapper.setData(data);
        return  responseWrapper;
    }

}
